package com.ksd.pug.clound.controller;

import com.ksd.pug.clound.pojo.SysUser;
import com.ksd.pug.clound.service.UserServiceFuture;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Future;

@RestController
@RequestMapping("/consumer")
public class UserController {

    @Autowired
    private UserServiceFuture userServiceFuture;

    @GetMapping("/usercompare")
    @HystrixCommand(fallbackMethod = "fallbackUser")
    public String getUser() {
        Future<SysUser> sysuser1 = userServiceFuture.getSysuser(1L);
        Future<SysUser> sysuser2 = userServiceFuture.getSysuser(2L);
        Future<SysUser> sysuser3 = userServiceFuture.getSysuser(3L);
        return "success";
    }

    /**
     * 细节1：方法返回值必须一模一样，
     * 细节2：参数也必须一模一样
     */
    public String fallbackUser() {
        System.out.println("出错了....");
        return "服务器忙!!!";
    }
}
